package com.nanhai.buddhist.college.module.collegebase.dal.mysql.classroominfo;

import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.mybatis.core.mapper.BaseMapperX;
import com.nanhai.buddhist.college.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.classroominfo.vo.ClassroomInfoExportReqVO;
import com.nanhai.buddhist.college.module.collegebase.controller.admin.classroominfo.vo.ClassroomInfoPageReqVO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.classroomcategory.ClassroomCategoryDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.classroominfo.ClassroomInfoDO;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.departments.DepartmentsDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 教室 Mapper
 *
 * @author 南海佛学院
 */
@Mapper
public interface ClassroomInfoMapper extends BaseMapperX<ClassroomInfoDO> {

    default PageResult<ClassroomInfoDO> selectPage(ClassroomInfoPageReqVO reqVO) {
        return selectPageForJoin(reqVO, ClassroomInfoDO.class,new MPJLambdaWrapperX<ClassroomInfoDO>()
                .eqIfPresent(ClassroomInfoDO::getDepartmentId, reqVO.getDepartmentId())
                .eqIfPresent(DepartmentsDO::getCollegeId, reqVO.getCollegeId())
                .eqIfPresent(ClassroomInfoDO::getTypeId, reqVO.getTypeId())
                .likeIfPresent(ClassroomInfoDO::getClassroomName, reqVO.getClassroomName())
                .leftJoin(ClassroomCategoryDO.class,ClassroomCategoryDO::getId,ClassroomInfoDO::getTypeId)
                .leftJoin(DepartmentsDO.class,DepartmentsDO::getId,ClassroomInfoDO::getDepartmentId)
                .selectAll(ClassroomInfoDO.class)
                .selectAs(ClassroomCategoryDO::getTypeName,ClassroomInfoDO::getCategoryName)
                .orderByDesc(ClassroomInfoDO::getCreateTime));
    }

    default List<ClassroomInfoDO> selectList(ClassroomInfoExportReqVO reqVO) {
        return selectJoinList(ClassroomInfoDO.class,new MPJLambdaWrapperX<ClassroomInfoDO>()
                .eqIfPresent(ClassroomInfoDO::getDepartmentId, reqVO.getDepartmentId())
                .eqIfPresent(ClassroomInfoDO::getTypeId, reqVO.getTypeId())
                .likeIfPresent(ClassroomInfoDO::getClassroomName, reqVO.getClassroomName())
                .leftJoin(ClassroomCategoryDO.class,ClassroomCategoryDO::getId,ClassroomInfoDO::getTypeId)
                .selectAll(ClassroomInfoDO.class)
                .selectAs(ClassroomCategoryDO::getTypeName,ClassroomInfoDO::getCategoryName)
                .orderByDesc(ClassroomInfoDO::getCreateTime));
    }

}
